import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HeroService } from '../../../../services/hero.service';
import { NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-printerinfo',
  templateUrl: './printerinfo.component.html',
  styleUrls: ['./printerinfo.component.css']
})
export class PrinterinfoComponent implements OnInit {

  public userinfo:string;
  public userbillinfo:string;
  public maintinfo:string;
  public radioValue:string="1";
  public data:Array<any>=[''];
  public datalist:Array<any>=[];
  public billlist:Array<any>=[];
  public tasklist:Array<any>=[];
  public config:Array<any>=[''];
  public user:Array<any>=[''];
  public PageIndex:number=1;
  public PageSize:number=6;
  public PageTotal:number;
  constructor(private heroService: HeroService,
              private route: ActivatedRoute,
              private modalService: NzModalService) { }

  ngOnInit() {
    this.getPrinterInfo(this.radioValue,true);
  }
  //获取打印机详情数据
  getPrinterInfo(type,getInfo){
    const id = this.route.snapshot.paramMap.get('id');
    let url1=host+"/main/merchantPrinter/view?id="+id+"&type=PrinterRecord"+"&getInfo="+getInfo+"&page="+this.PageIndex+"&pageSize="+this.PageSize;
    let url2=host+"/main/merchantPrinter/view?id="+id+"&type=PrinterBill"+"&getInfo="+getInfo+"&page="+this.PageIndex+"&pageSize="+this.PageSize;
    let url3=host+"/main/merchantPrinter/view?id="+id+"&type=TaskInfo"+"&getInfo="+getInfo+"&page="+this.PageIndex+"&pageSize="+this.PageSize;
    this.heroService.get(eval(`url${type}`)).then(result=>{
        if(result.code == 0){
          if(getInfo){
            this.data[0]=result.data.bean;
            this.config[0]=result.data.printerSet;
            this.user[0]=result.data.connectUser;
          }
          if(type == 1){
            this.datalist=result.data.PrinterRecord.pageBean.result;
            this.userinfo=result.data.PrinterRecord.connectUser;
            this.PageIndex=result.data.PrinterRecord.pageBean.curPage;  
            this.PageTotal=result.data.PrinterRecord.pageBean.totalRow;
          }
          if(type == 2){
            this.billlist=result.data.PrinterBill.pageBean.result;
            this.userbillinfo=result.data.PrinterBill.connectUser;
            this.PageIndex=result.data.PrinterBill.pageBean.curPage;  
            this.PageTotal=result.data.PrinterBill.pageBean.totalRow;
          }
          if(type == 3){
            this.tasklist=result.data.TaskInfo.pageBean.result;
            this.maintinfo=result.data.TaskInfo.connectMaint;
            this.PageIndex=result.data.TaskInfo.pageBean.curPage;  
            this.PageTotal=result.data.TaskInfo.pageBean.totalRow;
          }
        }else{
          this.modalService.error({
            nzTitle: '提示',
            nzContent: result.msg
          });
        }
    })
  }
  //监听数据
  getRadioValue(){
    console.log(this.radioValue);
    if(this.radioValue=="1"){
      this.getPrinterInfo(1,false);
    }
    if(this.radioValue=="2"){
      if(this.radioValue=="2"){
        this.getPrinterInfo(2,false);
      }
    }
    if(this.radioValue=="3"){
      if(this.radioValue=="3"){
        this.getPrinterInfo(3,false);
      }
    }
  }
  //分页
  PageIndexChange(event){
    this.PageIndex=event;
    this.getRadioValue();
  }
}
